package tree;

/**
 * @description: 赫弗曼树的节点类
 * @title: HuffmanNode
 * @author: zp
 * @date: 2021/12/14 19:58
 */
public class HuffmanNode implements Comparable<HuffmanNode>{
    public int weight;  //节点的权值
    public Byte data; //保存的字符
    public int flag;    //节点是否加入哈夫曼树的标志
    public HuffmanNode lChild, rChild;//父节点和左右孩子节点

    public HuffmanNode() {
        this(0);
    }

    public HuffmanNode(int weight) {
        this.weight = weight;
        flag = 1;
        lChild = rChild = null;
    }

    public HuffmanNode(int weight,Byte data) {
        this.weight = weight;
        this.data = data;
        flag = 1;
       lChild = rChild = null;
    }

    @Override
    public int compareTo(HuffmanNode o) {
        return this.weight-o.weight;
    }

    @Override
    public String toString() {
        return "HuffmanNode{" +
                "weight=" + weight +
                ", data=" + data +
                ", flag=" + flag +
                ", lChild=" + lChild +
                ", rChild=" + rChild +
                '}';
    }
}
